package com.leetcode;

public class L0226 {

    public TreeNode invertTree(TreeNode root) {
           if (root==null)
               return root;
           f(root);
           return root;
    }

    public void f(TreeNode root){
        if (root.left!=null || root.right!=null){
            TreeNode temp=root.left;
            root.left=root.right;
            root.right=temp;
        }
        if (root.left!=null)
           f(root.left);
        if (root.right!=null)
           f(root.right);
    }
}
